package com.ruoyi.web.controller.mall;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductAttributeType;
import com.ruoyi.product.service.IProductAttributeTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品属性类别Controller
 * 
 * @author lb
 * @date 2024-01-17
 */
@RestController
@RequestMapping("/mall/productAttributeType")
public class ProductAttributeTypeController extends BaseController
{
    @Autowired
    private IProductAttributeTypeService productAttributeTypeService;

    /**
     * 查询商品属性类别列表
     */
    @PreAuthorize("@ss.hasPermi('mall:productAttributeType:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductAttributeType productAttributeType)
    {
        startPage();
        List<ProductAttributeType> list = productAttributeTypeService.selectProductAttributeTypeList(productAttributeType);
        return getDataTable(list);
    }

    /**
     * 导出商品属性类别列表
     */
    @PreAuthorize("@ss.hasPermi('mall:productAttributeType:export')")
    @Log(title = "商品属性类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductAttributeType productAttributeType)
    {
        List<ProductAttributeType> list = productAttributeTypeService.selectProductAttributeTypeList(productAttributeType);
        ExcelUtil<ProductAttributeType> util = new ExcelUtil<ProductAttributeType>(ProductAttributeType.class);
        util.exportExcel(response, list, "商品属性类别数据");
    }

    /**
     * 获取商品属性类别详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:productAttributeType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productAttributeTypeService.selectProductAttributeTypeById(id));
    }

    /**
     * 新增商品属性类别
     */
    @PreAuthorize("@ss.hasPermi('mall:productAttributeType:add')")
    @Log(title = "商品属性类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductAttributeType productAttributeType)
    {
        return toAjax(productAttributeTypeService.insertProductAttributeType(productAttributeType));
    }

    /**
     * 修改商品属性类别
     */
    @PreAuthorize("@ss.hasPermi('mall:productAttributeType:edit')")
    @Log(title = "商品属性类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductAttributeType productAttributeType)
    {
        return toAjax(productAttributeTypeService.updateProductAttributeType(productAttributeType));
    }

    /**
     * 删除商品属性类别
     */
    @PreAuthorize("@ss.hasPermi('mall:productAttributeType:remove')")
    @Log(title = "商品属性类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productAttributeTypeService.deleteProductAttributeTypeByIds(ids));
    }
}
